*******************************************************************************
* Table A.2 - Balancing of covariates
*******************************************************************************

use  "Data_temp/turnout.dta", clear

	gen rel_age=.
	gen elec=.
	foreach x in 1992 1997 2001 2005 2010 2015 2017 {
		replace rel_age=age`x' if inrange(age`x',-24,23) & rel_age==.
		replace elec=`x' if inrange(age`x',-24,23) & elec==.
		}
	tab elec, gen(dummy)
	drop dummy1
	
snapshot erase _all
snapshot save	

* full list of potential covariates
sum  female england  scotland wales north_ireland white_brit born_abroad mwork14 mum_lowedu   urban
sum employed low_edu married // potentially endogenous

global female_label			"Female"
global england_label		"Region: England"
global scotland_label		"Region: Scotland"
global north_ireland_label	"Region: Northern Ireland"
global wales_label			"Region: Wales"
global white_brit_label		"Ethnicity: British or Irish White"
global born_abroad_label	"Born abroad"
global mwork14_label		"Mother worked when respondent was 14"
global mum_lowedu_label		"Mother with low education"
global low_edu_label		"Respondent with low education"
global employed_label		"Employed"
global urban_label			"Urban"
global married_label		"Married or in civil union"





estimates clear
cap erase "Tables/a_tb2.tex"

gen se=.
gen N=.
gen coef=.

foreach var in female born_abroad mwork14 mum_lowedu white_brit  employed low_edu married urban england  scotland wales north_ireland {
rdrobust `var' rel_age if rel_age!=0, covs(dummy*) p(1)  h(24 24)
	replace coef=e(tau_cl)
	replace se=e(se_tau_cl) 
	replace N= e(N_h_l)+ e(N_h_r)
reg coef
	est sto m1
reg se
	est sto m2
reg N
	est sto m3	

estout m* using "Tables/a_tb2.tex", ///
	style(tex) cells (b(fmt(%9.3f)))  varlabels(_cons "${`var'_label}")	  ///
mlabels(none	) ///
	collabels(none) eql(none) notype label append	
	}
	